package jp.ac.u_tokyo.dch.core.db;
/**
 * Statement ラッパクラス
 *
 * @version 1.1
 */
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;

import jp.ac.u_tokyo.dch.core.exceptions.DBException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CustomStatement {

	/** ロガー */
	private static Log logger = LogFactory.getLog(CustomStatement.class);

	/** Statement */
	private Statement stmt = null;

	/**
	 * コンストラクタ
	 * @param stmt Statement
	 */
	public CustomStatement(Statement stmt) {

		this.stmt = stmt;
	}

	public void addBatch(String sql) throws DBException {
		try {
			this.stmt.addBatch(sql);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void cancel() throws DBException {
		try {
			this.stmt.cancel();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void clearBatch() throws DBException {
		try {
			this.stmt.clearBatch();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void clearWarnings() throws DBException {
		try {
			this.stmt.clearWarnings();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void close() throws DBException {
		try {
			this.stmt.close();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public boolean execute(String sql) throws DBException {
		try {
			return this.stmt.execute(sql);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public boolean execute(String sql, int autoGeneratedKeys)
			throws DBException {
		try {
			return this.stmt.execute(sql, autoGeneratedKeys);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public boolean execute(String sql, int[] columnIndexes) throws DBException {
		try {
			return this.stmt.execute(sql, columnIndexes);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public boolean execute(String sql, String[] columnNames)
			throws DBException {
		try {
			return this.stmt.execute(sql, columnNames);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int[] executeBatch() throws DBException {
		try {
			return this.stmt.executeBatch();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public CustomResultSet executeQuery(String sql) throws DBException {
		try {
			ResultSet rs = this.stmt.executeQuery(sql);
			return new CustomResultSet(rs);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int executeUpdate(String sql) throws DBException {
		try {
			return this.stmt.executeUpdate(sql);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int executeUpdate(String sql, int autoGeneratedKeys)
			throws DBException {
		try {
			return this.stmt.executeUpdate(sql, autoGeneratedKeys);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int executeUpdate(String sql, int[] columnIndexes)
			throws DBException {
		try {
			return this.stmt.executeUpdate(sql, columnIndexes);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int executeUpdate(String sql, String[] columnNames)
			throws DBException {
		try {
			return this.stmt.executeUpdate(sql, columnNames);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public DBConnection getConnection() throws DBException {
		try {
			Connection con = this.stmt.getConnection();
			return new DBConnection(con);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getFetchDirection() throws DBException {
		try {
			return this.stmt.getFetchDirection();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getFetchSize() throws DBException {
		try {
			return this.stmt.getFetchSize();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public CustomResultSet getGeneratedKeys() throws DBException {
		try {
			ResultSet rs = this.stmt.getGeneratedKeys();
			return new CustomResultSet(rs);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getMaxFieldSize() throws DBException {
		try {
			return this.stmt.getMaxFieldSize();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getMaxRows() throws DBException {
		try {
			return this.stmt.getMaxRows();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public boolean getMoreResults() throws DBException {
		try {
			return this.stmt.getMoreResults();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public boolean getMoreResults(int current) throws DBException {
		try {
			return this.stmt.getMoreResults(current);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getQueryTimeout() throws DBException {
		try {
			return this.stmt.getQueryTimeout();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public CustomResultSet getResultSet() throws DBException {
		try {
			ResultSet rs  = this.stmt.getResultSet();
			return new CustomResultSet(rs);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getResultSetConcurrency() throws DBException {
		try {
			return this.stmt.getResultSetConcurrency();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getResultSetHoldability() throws DBException {
		try {
			return this.stmt.getResultSetHoldability();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getResultSetType() throws DBException {
		try {
			return this.stmt.getResultSetType();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getUpdateCount() throws DBException {
		try {
			return this.stmt.getUpdateCount();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public SQLWarning getWarnings() throws DBException {
		try {
			return this.stmt.getWarnings();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void setCursorName(String name) throws DBException {
		try {
			this.stmt.setCursorName(name);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setEscapeProcessing(boolean enable) throws DBException {
		try {
			this.stmt.setEscapeProcessing(enable);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setFetchDirection(int direction) throws DBException {
		try {
			this.stmt.setFetchDirection(direction);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setFetchSize(int rows) throws DBException {
		try {
			this.stmt.setFetchSize(rows);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setMaxFieldSize(int max) throws DBException {
		try {
			this.stmt.setMaxFieldSize(max);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setMaxRows(int max) throws DBException {
		try {
			this.stmt.setMaxRows(max);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setQueryTimeout(int seconds) throws DBException {
		try {
			this.stmt.setQueryTimeout(seconds);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

}
